package com.ruoyi.web.controller.Commerce.orders;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Shouhou;
import com.ruoyi.system.service.IShouhouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后管理Controller
 * 
 * @author vv
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/orders/shouhou")
public class ShouhouController extends BaseController
{
    @Autowired
    private IShouhouService shouhouService;

    /**
     * 查询售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shouhou shouhou)
    {
        startPage();
        List<Shouhou> list = shouhouService.selectShouhouList(shouhou);
        return getDataTable(list);
    }

    /**
     * 检查订单号是否重复
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:list')")
    @GetMapping("/checkOrderId")
    public Boolean checkOrderIdExists(@RequestParam String oId) {
        Boolean result = shouhouService.checkOrderIdExists(oId);
        System.out.println("订单号 " + oId + " 重复检查结果: " + result);
        return result;
    }




    /**
     * 导出售后管理列表
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:export')")
    @Log(title = "售后管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shouhou shouhou)
    {
        List<Shouhou> list = shouhouService.selectShouhouList(shouhou);
        ExcelUtil<Shouhou> util = new ExcelUtil<Shouhou>(Shouhou.class);
        util.exportExcel(response, list, "售后管理数据");
    }

    /**
     * 获取售后管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(shouhouService.selectShouhouById(id));
    }

    /**
     * 新增售后管理
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:add')")
    @Log(title = "售后管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shouhou shouhou)
    {
        return toAjax(shouhouService.insertShouhou(shouhou));
    }

    /**
     * 修改售后管理
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:edit')")
    @Log(title = "售后管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shouhou shouhou)
    {
        return toAjax(shouhouService.updateShouhou(shouhou));
    }

    /**
     * 删除售后管理
     */
    @PreAuthorize("@ss.hasPermi('orders:shouhou:remove')")
    @Log(title = "售后管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shouhouService.deleteShouhouByIds(ids));
    }
}
